export function debounce<T extends (...args: any[]) => void>(
  func: T,
  delay: number,
): (this: any, ...args: Parameters<T>) => void {
  let timeout: ReturnType<typeof setTimeout>
  return function (this: any, ...args: Parameters<T>): void {
    // eslint-disable-next-line ts/no-this-alias
    const context = this
    clearTimeout(timeout)
    timeout = setTimeout(() => func.apply(context, args), delay)
  }
}
